//
//  NewAddressCell.m
//  WOPrototype
//
//  Created by Olof Millberg on 2010-04-23.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "NewAddressCell.h"

@implementation NewAddressCell

@synthesize streetField;
@synthesize areaField;
@synthesize postalCodeField;
@synthesize cityField;
@synthesize delegate;

- (void)populateWithDataFromWorkOrder:(WorkOrder *)workOrder
{
	streetField.text = workOrder.address.street;
	areaField.text = workOrder.address.area;
	postalCodeField.text = workOrder.address.zipCode;
	cityField.text = workOrder.address.city;
}

#pragma mark UITextField Delegate Methods

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{	
	[textField resignFirstResponder];
	return YES;
}

- (void) textFieldDidEndEditing:(UITextField *)textField
{
	switch (textField.tag) 
	{
			//Street
		case 0:
			[delegate newAddressCell:self streetChanged:textField.text];
			break;
			//Area
		case 1:
			[delegate newAddressCell:self areaChanged:textField.text];
			break;
			//Postal Code
		case 2:
			[delegate newAddressCell:self postalCodeChanged:textField.text];
			break;
			//City	
		case 3:
			[delegate newAddressCell:self cityChanged:textField.text];
			break;
		default:
			break;
	}
	[textField resignFirstResponder];
}	

@end
